package main

import (
	"fmt"
	"strconv"
)

func largestPalindrome(n int) int {
	if n == 1 {
		return 9
	}
	n1 := ""
	n2 := ""
	for i := 0; i < n; i++ {
		n1 += "9"
		n2 += "9"
	}

	num1, _ := strconv.Atoi(n1)
	//num2 := num1

	//max := num1 * num2

	getReverse := func(num int) string {
		n := []byte(strconv.Itoa(num))
		for i := 0; i < len(n)/2; i++ {
			temp := n[i]
			n[i] = n[len(n)-1-i]
			n[len(n)-1-i] = temp
		}

		return string(n)
	}

	//checkIsHuiWen := func(numStr string) bool {
	//	mid := len(numStr) / 2
	//
	//	for i := 0; i < mid; i++ {
	//		if numStr[i] != numStr[len(numStr)-1-i] {
	//			return false
	//		}
	//	}
	//	return true
	//}
	//max := num1 * num1
	for i := num1; i > 0; i-- {
		huiwen := strconv.Itoa(i) + getReverse(i)
		atoi, _ := strconv.Atoi(huiwen)
		for j := num1; j > 0; j-- {
			if atoi/j > num1+1 {
				break
			}
			if atoi%j == 0 {
				return atoi % 1337
			}
		}
	}

	return -1
}

func main() {
	fmt.Println(largestPalindrome(6))

}
